<style>
    .layui-form-item .layui-input-inline {
    float: left;
    width: 131px;
    margin-right: 10px;
}
</style>

<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="form">
                    <div class="layui-form-item">
                        <!-- <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobNumberSearch" autocomplete="off" class="layui-input"
                                    id="jobNumber">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userNameSearch" autocomplete="off" class="layui-input"
                                    id="userName">
                            </div>
                        </div> -->

                        <div class="layui-inline">
                            <label class="layui-form-label">分组方式</label>
                            <div class="layui-input-inline">
                                <select name="groupType" lay-filter="clsSelects">
                                    <option value='nochoice'>不分组</option>
                                    <option value="hyfl_code">按数据库分组</option>
                                    <option value="dep_id">按机构用户分组</option>
                                    <option value="user_name">按用户名分组</option>
                                    <option value="resource_name">按数据源分组</option>
                                    <option value="resource_title">按标题分组</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline" id="word" style="left: 20px">
                            <label class="layui-form-label" id="userIdChoice">用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="groupValue" placeholder="请输入用户ID" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                       
                        <div class="layui-inline" style="left: 20px">
                            <label class="layui-form-label">选择日期</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="startTime" id="startTime" autocomplete="off" class="layui-input">
                            </div>
                            <label style="float: left;padding-top: 4px;padding-right: 4px;">_&nbsp;&nbsp;</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="endTime" id="endTime" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                       

                        <div class="layui-inline" style="left: 10px">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"
                                style="width:90px;height:38px;border:none;outline:none;position: relative;
                                background-color:#007bff;color:white":><i
                                    class="layui-icon"></i> 搜 索</button>

                            <!--<button type="submit" lay-submit="" class="layui-btn layui-btn-warm"
                                lay-filter="data-export-btn"
                                style="width:90px;background-color:#26B99A;;position: relative;top:17px; left: 200px">
                                <i class="layui-icon"></i> 导 出</button>-->
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <br>
        <div id="table" lay-filter="currentTableFilter">

        </div>
        <div id="page"></div>
    </div>
</div>


<script type="text/html" id="zizeng">
    {{((parseInt(shared.getCookie("page"))-1))*parseInt(shared.getCookie("pageSize"))+ d.LAY_TABLE_INDEX+1}}
   </script>
<script type="text/html" id="Bar5">
    {{#  if(d.hyfl_code===1){ }}
      <span>协同创新</span>
    {{#  } else if (d.hyfl_code===2){ }}
      <span>应急管理</span>
    {{# } else if (d.hyfl_code===3){  }}
      <span>期刊内刊</span>
  {{#  } }}
  
    </script>

<script>
     shared.setCookie("page",1)
     shared.setCookie("pageSize",10)
    layui.form.render();
    var tableBar = [
        { title: '序 号', templet:'#zizeng', width: '10%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '8%', align: "center" },
        { field: 'user_name', title: '姓 名',  width: '10%', align: "center" },
        { field: 'resource_title', title: '标 题',  width: '32%', align: "center" },
        { field: 'resource_name', title: '数 据 来 源',  width: '10%', align: "center" },
        { field: 'create_time', title: '访 问 时 间',  width: '20%', align: "center" },
    ]

    var tableBar2 = [
        { title: '序 号', templet:'#zizeng',  width: '20%', align: "center" },
        { field: 'user_name', title: '姓名',  width: '20%', align: "center" },
        { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '40%', align: "center" }
    ]

    var tableBar3 = [
        { title: '序 号', templet:'#zizeng',  width: '20%', align: "center" },
        { field: 'resource_name', title: '数 据 来 源',  width:'20%', align: "center" },
        // { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '40%', align: "center" }
    ]
    var tableBar4 = [
        { title: '序 号', templet:'#zizeng',  width: '20%', align: "center" },
        { field: 'resource_title', title: '标 题',  width:'50%', align: "center" },
        // { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '30%', align: "center" }
    ]
    var tableBar5 = [
        { title: '序 号', templet:'#zizeng',  width: '20%', align: "center" },
        { field: 'hyfl_code', title: '数据库',  width:'50%', align: "center", templet:'#Bar5' },
        // { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '30%', align: "center" }
    ]
    var tableBar6 = [
        { title: '序 号', templet:'#zizeng',  width: '20%', align: "center"},
        { field: 'departmentName', title: '机构用户',  width:'50%', align: "center" },
        // { field: 'user_id', title: '用 户 ID',  width: '20%', align: "center" },
        { field: 'countnumber', title: '合 计',  width: '30%', align: "center" }
    ]

    var laydate = layui.laydate;

    laydate.render({
        elem: '#startTime',
        format: 'yyyy-MM-dd',
        done: function (value, date, endDate) {
            var startDate = new Date(value).getTime();
            var endTime = new Date($('#endTime').val()).getTime();
            if (endTime < startDate) {
                layer.msg('结束时间不能小于开始时间');
                $('#startTime').val('');
            }
        }
    })

    laydate.render({ //结束时间
        elem: '#endTime',
        format: 'yyyy-MM-dd',
        done: function (value, date, endDate) {
            var startDate = new Date($('#startTime').val()).getTime();
            var endTime = new Date(value).getTime();
            if (endTime < startDate) {
                layer.msg('结束时间不能小于开始时间');
                $('#endTime').val('');
            }
        }

    })

    var initTableParams = {
        "groupType": "",
        "groupValue": "",
        "accessType": "浏览",
        "source": "",
        "orderType": "创建时间",
        "orderValue": "desc",
        "page": 1,
        "pageSize": 10
    }


    //封装 表格渲染方法
    function tableRender(tableBar, initTableParams) {
        layuiEx.tableRender(
            "/ViewLog/getDownLog",
            'table',
            'page',
            tableBar,
            initTableParams
        );
    }

    tableRender(tableBar, initTableParams)

    //检索事件
    layui.form.on('submit(data-search-btn)', function (params) {
        console.log(params.field.groupType)
        shared.setCookie("page",1)
     shared.setCookie("pageSize",10)
        if (params.field.groupType == "user_name") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar2,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "resource_name") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar3,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "resource_title") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar4,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "source": params.field.source,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "hyfl_code") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar5,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else if (params.field.groupType == "dep_id") {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar6,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "orderType": "count(*)",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
        else {
            layuiEx.tableRender(
                "/ViewLog/getDownLog",
                'table',
                'page',
                tableBar,
                {
                    "groupType": params.field.groupType,
                    "groupValue": params.field.groupValue,
                    "accessType": params.field.accessType,
                    "source": params.field.source,
                    "startTime":params.field.startTime,
                    "endTime":params.field.endTime,
                    "orderType": "创建时间",
                    "orderValue": "desc",
                    "page": 1,
                    "pageSize": 10
                }
            );
            return false
        }
    })

    //监听导出按钮
    layui.form.on('submit(data-export-btn)', function (data) {
        var groupType = data.field.groupType
        var groupValue = data.field.groupValue
        var source = data.field.source
        var accessType = data.field.accessType
        var orderType = "count(*)"
        var orderValue = "desc"
        var url = config.server + "/adminLog/exportViewDownloadLog?source=" + source + "&accessType=" + accessType + "&orderType=" + orderType + "&orderValue=" + orderValue + "&groupType=" + groupType + "&groupValue=" + groupValue
        window.location.href = url;
        return false;
    });

</script>